home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1996 February / EnigmA AMIGA RUN 04 (1996)(G.R. Edizioni)(IT)[!][issue 1996-02][Skylink CD III].iso / earcd / util4 / bytmrk20.lha / misc.c < prev    next >
C/C++ Source or Header  |  1995-11-03  |  2KB  |  73 lines

  1.  
  2. /*
  3. ** misc.c
  4. ** BYTEmark (tm)
  5. ** BYTE's Native Mode Benchmarks
  6. ** Rick Grehan, BYTE Magazine
  7. */
  8.  
  9. #include <stdio.h>
  10. #include "misc.h"
  11.  
  12. /***********************************************************
  13. **     MISCELLANEOUS BUT OTHERWISE NECESSARY ROUTINES     **
  14. ***********************************************************/
  15.  
  16. /****************************
  17. ** RANDOM NUMBER GENERATOR **
  18. *****************************
  19. ** This is a second-order linear congruential random number
  20. ** generator.  Its advantage is (of course) that it can be
  21. ** seeded and will thus produce repeatable sequences of
  22. ** random numbers.
  23. */
  24.  
  25. /****************************
  26. *         randwc()          *
  27. *****************************
  28. ** Returns signed long random modulo num.
  29. */
  30. long randwc(long num)
  31. {
  32.     return(randnum(0L)%num);
  33. }
  34.  
  35. /***************************
  36. **      abs_randwc()      **
  37. ****************************
  38. ** Same as randwc(), only this routine returns only
  39. ** positive numbers.
  40. */
  41. unsigned long abs_randwc(unsigned long num)
  42. {
  43. long temp;        /* Temporary storage */
  44.  
  45. temp=randwc(num);
  46. if(temp<0) temp=0L-temp;
  47.  
  48. return((unsigned long)temp);
  49. }
  50.  
  51. /****************************
  52. *        randnum()          *
  53. *****************************
  54. ** Second order linear congruential generator.
  55. ** Constants suggested by J. G. Skellam.
  56. ** If val==0, returns next member of sequence.
  57. **    val!=0, restart generator.
  58. */
  59. long randnum(long lngval)
  60. {
  61.     register long interm;
  62.     static long randw[2] = { 13L , 117L };
  63.  
  64.     if (lngval!=0L)
  65.     {    randw[0]=13L; randw[1]=117L; }
  66.  
  67.     interm=(randw[0]*254754L+randw[1]*529562L)%999563L;
  68.     randw[1]=randw[0];
  69.     randw[0]=interm;
  70.     return(interm);
  71. }
  72.  
  73.